<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/pages/commons/path.jsp"%>

<script type="text/javascript">
	function isValid() {
		$('#deptId').validatebox({
			required : true,
			missingMessage : '请输入有效的部门ID！'
		});
		
		$('#deptName').validatebox({
			required : true,
			missingMessage : '请输入有效的部门名称！'
		});
		
		$('#deptDesc').validatebox({
			required : true,
			precision : 0,
			missingMessage : '请输入有效的部门描述！'
		});
		
		$('#sort').numberbox({
			required : false
		});
		
		if (!$('#deptId').validatebox('isValid'))
			return false;
		
		if (!$('#deptName').validatebox('isValid'))
			return false;
		
		if (!$('#deptDesc').validatebox('isValid'))
			return false;
		
		return true;
	}

	function save() {
		if (!isValid())
			return;
		
		var deptId = $.trim($('#deptId').val());
		var deptName = $.trim($('#deptName').val());
		var deptDesc = $.trim($('#deptDesc').val());
		var sort = $.trim($('#sort').val());
		var pDeptId = $.trim($('#pDeptId').val());
		var reserve1 = $.trim($('#reserve1').val());
		var reserve2 = $.trim($('#reserve2').val());
		
		if (sort == null || sort.length == 0)
			sort = '0';

		$.ajax({
			type : 'post',
			url : '${ctx}/permission/userDept/doAdd.do',
			data : {
				deptId : deptId,
				deptName : deptName,
				deptDesc : deptDesc,
				sort : sort,
				pDeptId : pDeptId,
				reserve1 : reserve1,
				reserve2 : reserve2
			},
			dataType : 'json',
			success : function(data) {
				var result = data.result;
				if (result == 'success') {
					$.messager.alert('提示', '操作成功！', 'info');

					$('#editDiv').dialog('close');
					$('#dataTable').treegrid('reload');
					$('#dataTable').treegrid('clearChecked');
				} else {
					$.messager.alert('提示', '操作失败！<br />' + data.error, 'error');
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$.messager.alert('提示', '操作失败！<br />' + errorThrown, 'error');
			}
		});
	}
	
	function cancel() {
		$('#editDiv').dialog('close');
	}
</script>

<table class="table2">
	<tr>
		<td style="width: 80px">上级部门ID：</td>
		<td>
			${info.pDeptId}
			<input id="pDeptId" type="hidden" value="${info.pDeptId}" />
		</td>
	</tr>
	<tr>
		<td>部门ID：</td>
		<td><input id="deptId" type="text" style="width: 200px" maxLength="16" /></td>
	</tr>
	<tr>
		<td>部门名称：</td>
		<td><input id="deptName" type="text" style="width: 200px" maxLength="32" /></td>
	</tr>
	<tr>
		<td>部门描述：</td>
		<td><input id="deptDesc" type="text" style="width: 200px" maxLength="128" /></td>
	</tr>
	<tr>
		<td>排序号：</td>
		<td><input id="sort" type="text" style="width: 200px" maxLength="5" /></td>
	</tr>
	<tr>
		<td>保留字段1：</td>
		<td><input id="reserve1" type="text" style="width: 200px" maxLength="64" /></td>
	</tr>
	<tr>
		<td>保留字段2：</td>
		<td><input id="reserve2" type="text" style="width: 200px" maxLength="64" /></td>
	</tr>
	<tr>
		<td colspan="2" align="center">
			<a id="saveButton" class="easyui-linkbutton" icon="icon-ok" onclick="save()">确定</a>
			<a class="easyui-linkbutton" icon="icon-cancel" onclick="cancel()">取消</a>
		</td>
	</tr>
</table>